package com.spzx.order.reveiver;
/*
    并非全力
*/

import com.spzx.order.configure.OrderDelayedMqConfig;
import com.spzx.order.service.IOrderInfoService;
import com.spzx.rabbit.constant.MqConst;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.rabbitmq.client.Channel;

import java.io.IOException;
//关闭订单
@Component
public class OrderReceiver {
    @Autowired
    IOrderInfoService iorderInfoService;

//    @RabbitListener(bindings = @QueueBinding(
//            exchange = @Exchange(value = MqConst.EXCHANGE_CANCEL_ORDER,durable = "true"),
//            value = @Queue(value = MqConst.QUEUE_CANCEL_ORDER,durable = "true"),
//            key = {MqConst.ROUTING_CANCEL_ORDER}
//    ))
@RabbitListener(queues = OrderDelayedMqConfig.queue_delay_order)
    public void receiveOrder(Channel channel, Message message, String tradeNo) throws IOException {
        System.out.println("时间过期，未支付，关闭订单");
        iorderInfoService.cancelOrder(tradeNo);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);

    }
}
